﻿using System;
using System.Net;

namespace FileDownloader
{
    class FileDownloader
    {
        static void FileDownload(string url)
        {
            string fileName = url.Substring(url.LastIndexOf('/'));
            WebClient webClient = new WebClient();
            try
            {
                webClient.DownloadFile(new Uri(url), fileName);
            }
            catch (WebException)
            {
                Console.Error.WriteLine("The address is invalid.");
            }
            catch (NotSupportedException)
            {
                Console.Error.WriteLine("The method has been called simultaneously on multiple threads.");
            }
            catch (InvalidOperationException)
            {
                Console.Error.WriteLine("The file exists and is open.");
            }
            catch (UnauthorizedAccessException uoae)
            {
                Console.WriteLine(uoae.Message);
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("Invalid file path format!");
            }
            finally
            {
                webClient.Dispose();
            }
        }
        static void Main(string[] args)
        {
            FileDownload("http://www.devbg.org./img/Logo-BASD.jpg");
        }
    }
}
